summaryrefslogtreecommitdiffstats
path: root/src/common/android/applets/software_keyboard.h
blob: 9fd09d27c53db90318b840dced05225380fd507a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <jni.h>

#include "core/frontend/applets/software_keyboard.h"

namespace Common::Android::SoftwareKeyboard {

class AndroidKeyboard final : public Core::Frontend::SoftwareKeyboardApplet {
public:
    ~AndroidKeyboard() override;

    void Close() const override {
        ExitKeyboard();
    }

    void InitializeKeyboard(bool is_inline,
                            Core::Frontend::KeyboardInitializeParameters initialize_parameters,
                            SubmitNormalCallback submit_normal_callback_,
                            SubmitInlineCallback submit_inline_callback_) override;

    void ShowNormalKeyboard() const override;

    void ShowTextCheckDialog(Service::AM::Frontend::SwkbdTextCheckResult text_check_result,
                             std::u16string text_check_message) const override;

    void ShowInlineKeyboard(
        Core::Frontend::InlineAppearParameters appear_parameters) const override;

    void HideInlineKeyboard() const override;

    void InlineTextChanged(Core::Frontend::InlineTextParameters text_parameters) const override;

    void ExitKeyboard() const override;

    void SubmitInlineKeyboardText(std::u16string submitted_text);

    void SubmitInlineKeyboardInput(int key_code);

private:
    struct ResultData {
        static ResultData CreateFromFrontend(jobject object);

        std::string text;
        Service::AM::Frontend::SwkbdResult result{};
    };

    void SubmitNormalText(const ResultData& result) const;

    Core::Frontend::KeyboardInitializeParameters parameters{};

    mutable SubmitNormalCallback submit_normal_callback;
    mutable SubmitInlineCallback submit_inline_callback;

private:
    mutable bool m_is_inline_active{};
    std::u16string m_current_text;
};

// Should be called in JNI_Load
void InitJNI(JNIEnv* env);

// Should be called in JNI_Unload
void CleanupJNI(JNIEnv* env);

} // namespace Common::Android::SoftwareKeyboard

// Native function calls
extern "C" {
JNIEXPORT jobject JNICALL Java_org_citra_citra_1emu_applets_SoftwareKeyboard_ValidateFilters(
    JNIEnv* env, jclass clazz, jstring text);

JNIEXPORT jobject JNICALL Java_org_citra_citra_1emu_applets_SoftwareKeyboard_ValidateInput(
    JNIEnv* env, jclass clazz, jstring text);
}